<template>
  <el-container class="home_main">
    <el-header>
      <!-- 头部 -->

      <div class="header">
        <h1>move管理系统</h1>
        <div class="user_msg">
          <div class="user_photo">
            <img :src="$axios.defaults.baseURL + user.head_img" alt />
          </div>
          <p>{{user.nickname}}</p>
          <span @click="quit">退出</span>
        </div>
      </div>

      <!-- 头部 -->
    </el-header>
    <el-container>
      <el-aside width="200px">
        <!-- 侧面 -->
        <!-- <el-menu-item index="1-1" @click="$router.push('postList').catch(err=>{})">文章列表</el-menu-item> -->
        <!-- <el-menu-item index="1-2" @click="$router.push('sendPost').catch(err=>{})">发布文章</el-menu-item> -->

        <el-menu
        :router='true'
          default-active="$route.path"
          class="el-menu-vertical-demo"
          @open="handleOpen"
          @close="handleClose"
          background-color="#545c64"
          text-color="#fff"
          active-text-color="#ffd04b"
        >
          <el-menu-item index="/postList">
            <i class="el-icon-menu"></i>
            <span slot="title">文章列表</span>
          </el-menu-item>
          <el-menu-item index="/sendPost">
            <i class="el-icon-menu"></i>
            <span slot="title">发布文章</span>
          </el-menu-item>
        </el-menu>
        <!-- 侧面 -->
      </el-aside>
      <el-main>
        <!-- 面包屑 -->
        <div class="Breadcrumbs">
          <span
            v-for="(item,index) of $route.matched"
            :key="index"
            @click="$router.push({name:item.name}).catch(err=>{})"
          >{{ index == 0 ? item.name : '-->' + item.name }}</span>
        </div>
        <!-- 中间 -->
        <router-view></router-view>
        <!-- 中间 -->
      </el-main>
    </el-container>
  </el-container>
</template>

<script>
export default {
  data() {
    return {
      user: {}
    };
  },
  methods: {
    handleOpen(key, keyPath) {
      // console.log(key, keyPath);
    },
    handleClose(key, keyPath) {
      // console.log(key, keyPath);
    },
    get_user() {
      const id = +localStorage.getItem("user_id");
      this.$axios({
        method: "get",
        url: "/user/" + id
      }).then(res => {
        const { data } = res.data;
        this.user = data;
      });
    },
    quit() {
      localStorage.removeItem("token");
      localStorage.removeItem("user_id");
      this.$router.push({ path: "/login" });
    }
  },
  mounted() {
    this.get_user();
  }
};
</script>

<style lang="less" scoped>
.header {
  display: flex;
  justify-content: space-between;
  .user_msg {
    display: flex;
    justify-content: space-around;
    align-items: center;
    p {
      padding: 0 10px;
    }
    .user_photo {
      width: 50px;
      height: 50px;
      img {
        border-radius: 50%;
        width: 100%;
        height: 100%;
        background: #333;
      }
    }
  }
}
// 头部
// 面包屑
.Breadcrumbs {
  text-align: left;
  text-indent: 2em;
}
.home_main {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 100%;
}
.el-header,
.el-footer {
  background-color: #b3c0d1;
  color: #333;
  text-align: center;
  line-height: 60px;
}

.el-aside {
  background-color: #d3dce6;
  color: #333;
  text-align: center;
  line-height: 200px;
}

.el-main {
  background-color: #e9eef3;
  color: #333;
  // text-align: center;
  //   ! 重点
  line-height: 35px;
}

body > .el-container {
  margin-bottom: 40px;
}

.el-container:nth-child(5) .el-aside,
.el-container:nth-child(6) .el-aside {
  line-height: 260px;
}

.el-container:nth-child(7) .el-aside {
  line-height: 320px;
}
</style>